Skip to contentSkip to conversation

Change in openvpn[master]: dco_freebsd: implement dco_get_peer_stats()

Openvpn-devel In review cron2 (Code Review) 2 participants 7 messages Nov 4, 2025 – Nov 9, 2025 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1762292654000.I38a040a9bdcb44933d4ca538f746af5c61011d7c@...2715...

#1 lore raw

Attention is currently required from: flichtenheld, plaisthos.

Hello plaisthos, flichtenheld,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1350?usp=email

to review the following change.

Change subject: dco_freebsd: implement dco_get_peer_stats()
......................................................................

dco_freebsd: implement dco_get_peer_stats()

This is "fetch read/write statistics for a single peer", complementing dco_get_peer_stats_multi() "... for all peers", and it is called in --client mode, and (!) in p2mp mode to check if --inactive thresholds are reached.

The FreeBSD DCO module has no "give me stats for a single peer" call, so we just call dco_get_peer_stats_multi() to get all of them - and that function is modified to handle p2p or p2mp mode by checking mode == CM_TOP.

(dco_linux does about the same in dco_get_peer*() -> ovpn_handle_peer(), after a few iterations, except that it can query for "just one peer")

"--inactive" still does not work on FreeBSD, because the code in forward.c looks at counters that are not set by FreeBSD DCO.

Github: OpenVPN/openvpn#898

Change-Id I38a040a9bdcb44933d4ca538f746af5c61011d7c

---
M src/openvpn/dco_freebsd.c

1 file changed, 25 insertions(+), 4 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/50/1350/1

src/openvpn/dco_freebsd.c +25 -4
index e4cb71a..2131d9c 100644
@@ -870,8 +870,20 @@
     {
         const nvlist_t *peer = nvpeers[i];
         uint32_t peerid = nvlist_get_number(peer, "peerid");
+        const nvlist_t *bytes = nvlist_get_nvlist(peer, "bytes");
 
-        dco_update_peer_stat(dco->c->multi, peerid, nvlist_get_nvlist(peer, "bytes"));
+        /* we can end here in p2mp mode, or in p2p mode via
+         * the call to "dco_get_peer_stat()"
+         */
+        if (dco->c->mode == CM_TOP)
+        {
+            dco_update_peer_stat(dco->c->multi, peerid, bytes);
+        }
+        else
+        {
+            dco->c->c2.dco_read_bytes = nvlist_get_number(bytes, "in");
+            dco->c->c2.dco_write_bytes = nvlist_get_number(bytes, "out");
+        }
     }
 
     nvlist_destroy(nvl);
@@ -882,12 +894,21 @@
 #pragma GCC diagnostic pop
 #endif
 
+/* get stats for a single peer
+ * we can get here for "the peer stats" in p2p client mode, or by
+ * being queried for a particular peer in p2mp mode, for --inactive
+ */
 int
 dco_get_peer_stats(struct context *c, const bool raise_sigusr1_on_err)
 {
-    msg(D_DCO_DEBUG, __func__);
-    /* Not implemented. */
-    return 0;
+    ASSERT(c->c2.tls_multi);
+    msg(D_DCO_DEBUG, "%s: peer-id %d", __func__, c->c2.tls_multi->dco_peer_id);
+
+    /* unfortunately, the FreeBSD kernel has no peer-specific query - so
+     * we just get all the stats - and if we're there anyway, we can save it
+     * for all peers, too...
+     */
+    return dco_get_peer_stats_multi(&c->c1.tuntap->dco, raise_sigusr1_on_err);
 }
 
 const char *

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1350?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I38a040a9bdcb44933d4ca538f746af5c61011d7c
Gerrit-Change-Number: 1350
Gerrit-PatchSet: 1
Gerrit-Owner: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

Hello flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1350?usp=email

to look at the new patch set (#2).

Change subject: dco_freebsd: implement dco_get_peer_stats()
......................................................................

dco_freebsd: implement dco_get_peer_stats()

This is "fetch read/write statistics for a single peer", complementing dco_get_peer_stats_multi() "... for all peers", and it is called in --client mode, and (!) in p2mp mode to check if --inactive thresholds are reached.

The FreeBSD DCO module has no "give me stats for a single peer" call, so we just call dco_get_peer_stats_multi() to get all of them - and that function is modified to handle p2p or p2mp mode by checking mode == CM_TOP.

(dco_linux does about the same in dco_get_peer*() -> ovpn_handle_peer(), after a few iterations, except that it can query for "just one peer")

"--inactive" still does not work on FreeBSD, because the code in forward.c looks at counters that are not set by FreeBSD DCO.

v2:
on AUTH_FAIL, 'dco' struct is not initialized yet -> SIGSEGV crash, verify that dco_peer_id is >= 0 before calling dco_get_peer_stats_multi()

Github: OpenVPN/openvpn#898

Change-Id I38a040a9bdcb44933d4ca538f746af5c61011d7c

---
M src/openvpn/dco_freebsd.c

1 file changed, 30 insertions(+), 4 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/50/1350/2

src/openvpn/dco_freebsd.c +30 -4
index e4cb71a..9a824ff 100644
@@ -870,8 +870,20 @@
     {
         const nvlist_t *peer = nvpeers[i];
         uint32_t peerid = nvlist_get_number(peer, "peerid");
+        const nvlist_t *bytes = nvlist_get_nvlist(peer, "bytes");
 
-        dco_update_peer_stat(dco->c->multi, peerid, nvlist_get_nvlist(peer, "bytes"));
+        /* we can end here in p2mp mode, or in p2p mode via
+         * the call to "dco_get_peer_stat()"
+         */
+        if (dco->c->mode == CM_TOP)
+        {
+            dco_update_peer_stat(dco->c->multi, peerid, bytes);
+        }
+        else
+        {
+            dco->c->c2.dco_read_bytes = nvlist_get_number(bytes, "in");
+            dco->c->c2.dco_write_bytes = nvlist_get_number(bytes, "out");
+        }
     }
 
     nvlist_destroy(nvl);
@@ -882,12 +894,26 @@
 #pragma GCC diagnostic pop
 #endif
 
+/* get stats for a single peer
+ * we can get here for "the peer stats" in p2p client mode, or by
+ * being queried for a particular peer in p2mp mode, for --inactive
+ */
 int
 dco_get_peer_stats(struct context *c, const bool raise_sigusr1_on_err)
 {
-    msg(D_DCO_DEBUG, __func__);
-    /* Not implemented. */
-    return 0;
+    ASSERT(c->c2.tls_multi);
+    msg(D_DCO_DEBUG, "%s: peer-id %d", __func__, c->c2.tls_multi->dco_peer_id);
+
+    if (c->c2.tls_multi->dco_peer_id < 0)
+    {
+        return -EINVAL; /* DCO not active yet */
+    }
+
+    /* unfortunately, the FreeBSD kernel has no peer-specific query - so
+     * we just get all the stats - and if we're there anyway, we can save it
+     * for all peers, too...
+     */
+    return dco_get_peer_stats_multi(&c->c1.tuntap->dco, raise_sigusr1_on_err);
 }
 
 const char *

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1350?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I38a040a9bdcb44933d4ca538f746af5c61011d7c
Gerrit-Change-Number: 1350
Gerrit-PatchSet: 2
Gerrit-Owner: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>

#3 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld, plaisthos.

ralf_lici has posted comments on this change by cron2. ( http://gerrit.openvpn.net/c/openvpn/+/1350?usp=email )

Change subject: dco_freebsd: implement dco_get_peer_stats()
......................................................................

Patch Set 3: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1350?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I38a040a9bdcb44933d4ca538f746af5c61011d7c
Gerrit-Change-Number: 1350
Gerrit-PatchSet: 3
Gerrit-Owner: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: ralf_lici <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Sun, 09 Nov 2025 08:02:20 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes

#4 lore raw

PATCH v3 1/1 dco_freebsd: implement dco_get_peer_stats()

In reply to a message not in the archive

This is "fetch read/write statistics for a single peer", complementing dco_get_peer_stats_multi() "... for all peers", and it is called in --client mode, and (!) in p2mp mode to check if --inactive thresholds are reached.

The FreeBSD DCO module has no "give me stats for a single peer" call, so we just call dco_get_peer_stats_multi() to get all of them - and that function is modified to handle p2p or p2mp mode by checking mode == CM_TOP.

(dco_linux does about the same in dco_get_peer*() -> ovpn_handle_peer(), after a few iterations, except that it can query for "just one peer")

"--inactive" still does not work on FreeBSD, because the code in forward.c looks at counters that are not set by FreeBSD DCO.

v2:
on AUTH_FAIL, 'dco' struct is not initialized yet -> SIGSEGV crash, verify that dco_peer_id is >= 0 before calling dco_get_peer_stats_multi()

Github: OpenVPN/openvpn#898

Change-Id I38a040a9bdcb44933d4ca538f746af5c61011d7c

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1350
---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1350
This mail reflects revision 3 of this Change.

Acked-by according to Gerrit (reflected above):
Ralf Lici <[email protected]...>

src/openvpn/dco_freebsd.c +30 -4
index f80b6df..21f0ac0 100644
@@ -870,8 +870,20 @@
     {
         const nvlist_t *peer = nvpeers[i];
         uint32_t peerid = nvlist_get_number(peer, "peerid");
+        const nvlist_t *bytes = nvlist_get_nvlist(peer, "bytes");
 
-        dco_update_peer_stat(dco->c->multi, peerid, nvlist_get_nvlist(peer, "bytes"));
+        /* we can end here in p2mp mode, or in p2p mode via
+         * the call to "dco_get_peer_stat()"
+         */
+        if (dco->c->mode == CM_TOP)
+        {
+            dco_update_peer_stat(dco->c->multi, peerid, bytes);
+        }
+        else
+        {
+            dco->c->c2.dco_read_bytes = nvlist_get_number(bytes, "in");
+            dco->c->c2.dco_write_bytes = nvlist_get_number(bytes, "out");
+        }
     }
 
     nvlist_destroy(nvl);
@@ -882,12 +894,26 @@
 #pragma GCC diagnostic pop
 #endif
 
+/* get stats for a single peer
+ * we can get here for "the peer stats" in p2p client mode, or by
+ * being queried for a particular peer in p2mp mode, for --inactive
+ */
 int
 dco_get_peer_stats(struct context *c, const bool raise_sigusr1_on_err)
 {
-    msg(D_DCO_DEBUG, __func__);
-    /* Not implemented. */
-    return 0;
+    ASSERT(c->c2.tls_multi);
+    msg(D_DCO_DEBUG, "%s: peer-id %d", __func__, c->c2.tls_multi->dco_peer_id);
+
+    if (c->c2.tls_multi->dco_peer_id < 0)
+    {
+        return -EINVAL; /* DCO not active yet */
+    }
+
+    /* unfortunately, the FreeBSD kernel has no peer-specific query - so
+     * we just get all the stats - and if we're there anyway, we can save it
+     * for all peers, too...
+     */
+    return dco_get_peer_stats_multi(&c->c1.tuntap->dco, raise_sigusr1_on_err);
 }
 
 const char *
#5 lore raw

[Openvpn-devel] [PATCH applied] Re: dco_freebsd: implement dco_get_peer_stats()

Thanks for the review.

Re-Tested on FreeBSD 14.3 + DCO, still works :-)

Patch has been applied to the master branch.

commit ce99cd6cfc091e17701b471a88644cb45ab21681

Author: Gert Doering
Date:   Sun Nov 9 09:41:23 2025 +0100
     dco_freebsd: implement dco_get_peer_stats()

     Signed-off-by: Gert Doering <[email protected]...>
     Acked-by: Ralf Lici <[email protected]...>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1350
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg34273.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#6 lore raw
In reply to a message not in the archive

Hello flichtenheld, plaisthos, ralf_lici,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1350?usp=email

to look at the new patch set (#4).

The following approvals got outdated and were removed:
Code-Review+2 by ralf_lici

Change subject: dco_freebsd: implement dco_get_peer_stats()
......................................................................

dco_freebsd: implement dco_get_peer_stats()

This is "fetch read/write statistics for a single peer", complementing dco_get_peer_stats_multi() "... for all peers", and it is called in --client mode, and (!) in p2mp mode to check if --inactive thresholds are reached.

The FreeBSD DCO module has no "give me stats for a single peer" call, so we just call dco_get_peer_stats_multi() to get all of them - and that function is modified to handle p2p or p2mp mode by checking mode == CM_TOP.

(dco_linux does about the same in dco_get_peer*() -> ovpn_handle_peer(), after a few iterations, except that it can query for "just one peer")

"--inactive" still does not work on FreeBSD, because the code in forward.c looks at counters that are not set by FreeBSD DCO.

v2:
on AUTH_FAIL, 'dco' struct is not initialized yet -> SIGSEGV crash, verify that dco_peer_id is >= 0 before calling dco_get_peer_stats_multi()

Github: OpenVPN/openvpn#898

Change-Id I38a040a9bdcb44933d4ca538f746af5c61011d7c

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1350
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg34273.html

---
M src/openvpn/dco_freebsd.c

1 file changed, 30 insertions(+), 4 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/50/1350/4

src/openvpn/dco_freebsd.c +30 -4
index f80b6df..21f0ac0 100644
@@ -870,8 +870,20 @@
     {
         const nvlist_t *peer = nvpeers[i];
         uint32_t peerid = nvlist_get_number(peer, "peerid");
+        const nvlist_t *bytes = nvlist_get_nvlist(peer, "bytes");
 
-        dco_update_peer_stat(dco->c->multi, peerid, nvlist_get_nvlist(peer, "bytes"));
+        /* we can end here in p2mp mode, or in p2p mode via
+         * the call to "dco_get_peer_stat()"
+         */
+        if (dco->c->mode == CM_TOP)
+        {
+            dco_update_peer_stat(dco->c->multi, peerid, bytes);
+        }
+        else
+        {
+            dco->c->c2.dco_read_bytes = nvlist_get_number(bytes, "in");
+            dco->c->c2.dco_write_bytes = nvlist_get_number(bytes, "out");
+        }
     }
 
     nvlist_destroy(nvl);
@@ -882,12 +894,26 @@
 #pragma GCC diagnostic pop
 #endif
 
+/* get stats for a single peer
+ * we can get here for "the peer stats" in p2p client mode, or by
+ * being queried for a particular peer in p2mp mode, for --inactive
+ */
 int
 dco_get_peer_stats(struct context *c, const bool raise_sigusr1_on_err)
 {
-    msg(D_DCO_DEBUG, __func__);
-    /* Not implemented. */
-    return 0;
+    ASSERT(c->c2.tls_multi);
+    msg(D_DCO_DEBUG, "%s: peer-id %d", __func__, c->c2.tls_multi->dco_peer_id);
+
+    if (c->c2.tls_multi->dco_peer_id < 0)
+    {
+        return -EINVAL; /* DCO not active yet */
+    }
+
+    /* unfortunately, the FreeBSD kernel has no peer-specific query - so
+     * we just get all the stats - and if we're there anyway, we can save it
+     * for all peers, too...
+     */
+    return dco_get_peer_stats_multi(&c->c1.tuntap->dco, raise_sigusr1_on_err);
 }
 
 const char *

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1350?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I38a040a9bdcb44933d4ca538f746af5c61011d7c
Gerrit-Change-Number: 1350
Gerrit-PatchSet: 4
Gerrit-Owner: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: ralf_lici <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>

#7 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1350?usp=email )

Change subject: dco_freebsd: implement dco_get_peer_stats()
......................................................................

dco_freebsd: implement dco_get_peer_stats()

This is "fetch read/write statistics for a single peer", complementing dco_get_peer_stats_multi() "... for all peers", and it is called in --client mode, and (!) in p2mp mode to check if --inactive thresholds are reached.

The FreeBSD DCO module has no "give me stats for a single peer" call, so we just call dco_get_peer_stats_multi() to get all of them - and that function is modified to handle p2p or p2mp mode by checking mode == CM_TOP.

(dco_linux does about the same in dco_get_peer*() -> ovpn_handle_peer(), after a few iterations, except that it can query for "just one peer")

"--inactive" still does not work on FreeBSD, because the code in forward.c looks at counters that are not set by FreeBSD DCO.

v2:
on AUTH_FAIL, 'dco' struct is not initialized yet -> SIGSEGV crash, verify that dco_peer_id is >= 0 before calling dco_get_peer_stats_multi()

Github: OpenVPN/openvpn#898

Change-Id I38a040a9bdcb44933d4ca538f746af5c61011d7c

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1350
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg34273.html

---
M src/openvpn/dco_freebsd.c

1 file changed, 30 insertions(+), 4 deletions(-)
src/openvpn/dco_freebsd.c +30 -4
index f80b6df..21f0ac0 100644
@@ -870,8 +870,20 @@
     {
         const nvlist_t *peer = nvpeers[i];
         uint32_t peerid = nvlist_get_number(peer, "peerid");
+        const nvlist_t *bytes = nvlist_get_nvlist(peer, "bytes");
 
-        dco_update_peer_stat(dco->c->multi, peerid, nvlist_get_nvlist(peer, "bytes"));
+        /* we can end here in p2mp mode, or in p2p mode via
+         * the call to "dco_get_peer_stat()"
+         */
+        if (dco->c->mode == CM_TOP)
+        {
+            dco_update_peer_stat(dco->c->multi, peerid, bytes);
+        }
+        else
+        {
+            dco->c->c2.dco_read_bytes = nvlist_get_number(bytes, "in");
+            dco->c->c2.dco_write_bytes = nvlist_get_number(bytes, "out");
+        }
     }
 
     nvlist_destroy(nvl);
@@ -882,12 +894,26 @@
 #pragma GCC diagnostic pop
 #endif
 
+/* get stats for a single peer
+ * we can get here for "the peer stats" in p2p client mode, or by
+ * being queried for a particular peer in p2mp mode, for --inactive
+ */
 int
 dco_get_peer_stats(struct context *c, const bool raise_sigusr1_on_err)
 {
-    msg(D_DCO_DEBUG, __func__);
-    /* Not implemented. */
-    return 0;
+    ASSERT(c->c2.tls_multi);
+    msg(D_DCO_DEBUG, "%s: peer-id %d", __func__, c->c2.tls_multi->dco_peer_id);
+
+    if (c->c2.tls_multi->dco_peer_id < 0)
+    {
+        return -EINVAL; /* DCO not active yet */
+    }
+
+    /* unfortunately, the FreeBSD kernel has no peer-specific query - so
+     * we just get all the stats - and if we're there anyway, we can save it
+     * for all peers, too...
+     */
+    return dco_get_peer_stats_multi(&c->c1.tuntap->dco, raise_sigusr1_on_err);
 }
 
 const char *

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1350?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I38a040a9bdcb44933d4ca538f746af5c61011d7c
Gerrit-Change-Number: 1350
Gerrit-PatchSet: 4
Gerrit-Owner: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: ralf_lici <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>